﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using JUtil;
using System.Web.Hosting;

/// <summary>
/// ImageListHelper 的摘要描述
/// </summary>
public static class ImageListHelper
{
    public static DataTable GetDataSource()
    {
        string key = "FESTIVAL_ACTIVITY_ITEM";
        object FESTIVAL_ACTIVITY_ITEM = JUtil.Web.StateManagement.Session[key];
        if (FESTIVAL_ACTIVITY_ITEM != null)
            return (DataTable)FESTIVAL_ACTIVITY_ITEM;
        else
        {
            DbProvider DbProvider = DbProvider.Oracle;
            string connectionString = "Data Source=tppddb;User ID=tpdbuser;Password=tpdbuser;";
            IDatabase db = DbUtil.GetDbObject(new DbConnectionConfig
            {
                DbProvider = DbProvider,
                ConnectionString = connectionString
            });

            DataTable dt = db.SelectSQL("SELECT * FROM FESTIVAL_ACTIVITY_ITEM");
            JUtil.Web.StateManagement.Session.Add(key, dt);
            return dt;
        }
    }
}

public static class AspxConverter
{
    

    public static string FileNameToImageUrl(object oFileName)
    {
        string imageUrl = string.Empty;
        try
        {
            string fileName = Convert.ToString(oFileName);

            string VirImageRootPath = @"~/FestivalTicketSystem/UploadFiles";
            string imageRootPath = HostingEnvironment.MapPath(VirImageRootPath);


            string imagePath = JUtil.Path.File.GetAbsolutePath(imageRootPath, fileName);

            bool hasFile = !string.IsNullOrEmpty(fileName) && JUtil.Path.File.Exists(imagePath);
            if (!hasFile)
            {
                string DefImageFileName = @"NO_FILE.JPG";
                fileName = DefImageFileName;
            }

            imageUrl = string.Format("{0}/{1}", VirImageRootPath, fileName);
        }
        catch (Exception ex)
        {
            Log.ReportError(ex);
        }
        return imageUrl;
    }
}